﻿@*新增作业页面*@
@using EasyCourse.Model;
@{
    Layout = null;
    CommonPageInfo pageInfo = ViewData[CommonViewDataKey.CommonPageInfo] as CommonPageInfo;
    string para = "CourseId=" + pageInfo.CourseId;
}

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>新增作业</title>
    @Html.Partial("~/Views/Share/PublicHeader.cshtml")
    <link href="../Content/bootstrap/css/font-awesome.min.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" media="all" href="../css/daterangepicker-bs3.css" />
</head>
<body>
    @Html.Partial("~/Views/Share/PublicTopNav4Teacher.cshtml")
    <div class="container">
        <div class="row">
            <h1 class="topTitle-h1">@pageInfo.CourseName<br><small>广州中医药大学康复治疗微课程网络学习平台</small></h1>
        </div>
    </div>
    @*导航菜单*@
    @Html.Partial("~/Views/Share/PublicTeacherNaviMenu.cshtml", 1)
    <div class="container mainwrap">
        <div class="row">
            <div class="col-xs-2">
                <div class="dropdown theme-dropdown clearfix">
                    <a id="dropdownMenu1" href="#" role="button" class="sr-only dropdown-toggle" data-toggle="dropdown">Dropdown <span class="caret"></span></a>
                    <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
                        <li role="presentation">
                            <a role="menuitem" tabindex="-1" href="/AssignmentManage/List?@para">
                                <span class="glyphicon glyphicon-th-list"></span> 作业列表
                            </a>
                        </li>
                        <li role="presentation" class="divider"></li>
                        <li class="active" role="presentation">
                            <a role="menuitem" tabindex="-1" href="javascript:void(0)">
                                <span class="glyphicon glyphicon-plus"></span> 新增作业
                            </a>
                        </li>
                    </ul>
                </div>
            </div>
            <div class="col-xs-10">
                <div class="panel panel-default mainwrap-part">
                    <div class="panel-heading">
                        <h3 class="panel-title">
                            <ol class="breadcrumb">
                                <li>作业管理</li>
                                <li class="active">新增作业</li>
                            </ol>
                        </h3>
                    </div>
                    <div class="panel-body">
                        <div class="row">
                            <form role="form" class="form-horizontal">
                                <div class="form-group clearfix">
                                    <label for="courseTitle" class="col-xs-2 control-label">作业标题：</label>
                                    <div class="col-xs-4">
                                        <input type="text" class="form-control input-md" id="courseTitle" placeholder="请输入作业名称">
                                    </div>
                                </div>
                                <div class="form-group clearfix">
                                    <label for="studentsGroup" class="col-xs-2 control-label">学生组：</label>
                                    <div class="col-xs-4">
                                        <button type="button" data-target="#myModal" class="btn dropdown-toggle" id="studentsGroup" data-toggle="modal"><span class="groupName">请选择学生组名</span> <span class="caret"></span>
   </button>
                                    </div>
                                </div>
                                <div class="form-group clearfix">
                                    <label for="courseIntro" class="col-xs-2 control-label">作业简介：</label>
                                    <div class="col-xs-10">
                                        <textarea class="form-control" rows="6" id="courseIntro"></textarea>
                                    </div>
                                </div>
                                <div class="form-group clearfix">
                                    <label for="JfileName" class="col-xs-2 control-label">作业附件：</label>
                                    <div class="col-xs-4">
                                        <input name="fileName" id="JfileName" class="form-control mb10" readonly="readonly" />                                            
                                        <input id="file_upload" name="file_upload" type="file" class="form-control input-sm">
                                    </div>
                                </div>
                                <div class="form-group clearfix">
                                    <label for="releaseState" class="col-xs-2 control-label">是否发布：</label>
                                    <div class="col-xs-4">
                                        <select class="form-control" id="releaseState">
                                            <option value="0" selected>否</option>
                                            <option value="1">是</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group clearfix">
                                    <label for="deadline" class="col-xs-2 control-label">截止时间：</label>
                                    <div class="col-xs-4">
                                        <div class="input-prepend input-group">
                                            <span class="add-on input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
                                            <input type="text" name="deadline" id="deadline" class="form-control" value="" />
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group clearfix">
                                    <div class="col-xs-offset-2 col-xs-10">
                                        <button type="button" class="btn btn-success" id="saveBtn">保存</button>
                                        <button type="button" onclick="history.go(-1)" class="btn btn-success btn-md"><span class="glyphicon glyphicon-arrow-left"></span>返回</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!--学生组弹出框-->
    <div class="modal fade custom" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
      <div class="modal-dialog">
      <div class="modal-content">
         <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            <h5 class="modal-title" id="myModalLabel">学生组名</h5>
         </div>
         <div class="modal-body">
            <form role="form">
                <div class="row">
                    <div class="col-xs-8">
                        <div class="form-group">
                            <input type="text" id="studentG" class="form-control input-sm" placeholder="请输入学生组名"/>
                        </div>
                    </div>
                    <div class="col-xs-4"><button type="button" class="btn btn-sm btn-success" id="searchSG">搜索</button></div>
                </div>
            </form>
             <div class="resultList" id="resultList">
                <ul class="list-group" id="listgroup1">
                </ul>
                 <div class="clearfix" id="well">
                            <div class="pull-left sum" id="PagInfo"></div>
                            <div class=" center-block clearfix pull-right">
                                <ul class="pagination" id="PageTool"></ul>
                            </div>
                        </div>
             </div>
         </div>
         <div class="modal-footer">
            <button type="button" class="btn btn-primary btn-sm" id="confirmGrpName">确定</button>
            <button type="button" class="btn btn-default btn-sm" data-dismiss="modal">取消</button>
         </div>
      </div><!-- /.modal-content -->
      </div>
    </div><!-- /.modal -->
    @Html.Partial("~/Views/Share/PublicFooter.cshtml")
    @Html.Partial("~/Views/Share/PublicCommonJs.cshtml")
    <script type="text/javascript" src="../Content/uploadify/jquery.uploadify.min.js?time=@DateTime.Now.Ticks"></script>
    <link href="../Css/uploadify.css" rel="stylesheet" />
    <!--moment.js与daterangepicker.js为日历插件-->
    <script src="../Content/datepicker/moment.js"></script>
    <script src="../Content/datepicker/daterangepicker.js"></script>
    <script>
        var $studentG, $listgroup1, GrpName = "",searchId,searchtxt;
        $(function () {
            $studentG = $("#studentG"), $listgroup1 = $("#listgroup1");
            $(window).scroll(function () {
                if ($(window).scrollTop() >= 300) {
                    $('.actGotop').fadeIn(300);
                } else {
                    $('.actGotop').fadeOut(300);
                }
            });
            $('.actGotop').click(function () { $('html,body').animate({ scrollTop: '0px' }, 800); });
            var date = new Date(), y = date.getFullYear(), m = date.getMonth() + 1, d = date.getDate(), h = date.getHours(), min = date.getMinutes(),str="";
            str = y + "/" + ((m < 10) ? ("0" + m) : m) + "/" + ((d < 10) ? ("0" + d) : d) + " " + ((h > 12) ? (h - 12) : h) + ":" + ((min < 10) ? ("0" + min) : min) + " " + ((h > 12) ? "下午" : "上午");
            $('#deadline').val(str);
            $('#deadline').daterangepicker({ singleDatePicker: true, format: 'YYYY/MM/DD h:mm A', timePicker: true }, function (start, end, label) {
                
            }); 
        //上传文件
        var _attachmentUrl = null;
            $("#file_upload").uploadify({
                'queueSizeLimit': 1,
                //fileType代表文件类型的值可能有:   Image 、 OtherFile 、 Temp
                'formData': { 'fileType': 'OtherFile' },
                'buttonText': '请选择上传文件',
                'swf': '../Content/uploadify/uploadify.swf',
                'uploader': '@Url.Action("UpLoad", "Base")',
                'onUploadSuccess': function (file, data, response) {
                    var json = $.parseJSON(data);
                    if (json.result) {
                        _attachmentUrl = json.message; //文件保存的地址
                        $("#JfileName").val(file.name);
                        $("#JfileName").attr("data-fileUrl", _attachmentUrl);
                    }
                    else {
                        showTips.open(json.message);
                    }
                }

            });
            //提交新增作业
            $("#saveBtn").bind("click", function () {
                var Jfile = $("#JfileName").attr("data-fileUrl"),  //作业附件
                    courseTitle = $("#courseTitle").val(),
                    studentsGroup = $("#studentsGroup .groupName").attr("data"),
                    courseIntro = $("#courseIntro").val(),
                    releaseState = $("#releaseState").val();  //是否发布
                    deadline = $("#deadline").val(),   //截止时间
                    courseId = $.getUrlParam("CourseId");
                $.easyPost("@Url.Action("AddAssignment", "AssignmentManage")", {
                    "Title": courseTitle,
                    "Remark": courseIntro,
                    "GroupId": studentsGroup,
                    "CourseId": courseId,
                    "AttachmentUrl":Jfile,
                    "Status": releaseState,
                    "DeadTime": deadline
                }, function (data) {
                    if (data.result) {
                        showTips.open("添加成功！");
                        $("#courseTitle").val(""),
                        $("#studentsGroup .groupName").text("请选择学生组名").attr("data", ""),
                        $("#courseIntro").val(""),
                        $("#releaseState").val("0");
                        $("#JfileName").attr("data-fileUrl",null).val("");
                        return;
                    } else {
                        showTips.open(data.message);
                        return;
                    }
                }, "json")
            });
            getResults(1);
            //模态框查询，每次开启新查询，初始化一次模态框（即输入框，查询列表初始化）
            $("#searchSG").bind("click", function () {
                //若无数据，则提示没有匹配的学生组，若有数据则解析
                getResults(1);
            });
            $listgroup1.delegate("li", "click", function () {
                $(this).addClass("active").siblings().removeClass("active");
            });
            //确定按钮点击之后，赋予学生组选择按钮选中的值，并关闭模态框。
            $("#confirmGrpName").bind("click", function () {
                var tmpEle = $listgroup1.find(".active");
                if (tmpEle.size == 0) { showTips.open("您并未选中中任何学生组"); return;}
                searchId = tmpEle.attr("data");
                searchtxt = tmpEle.text();  /*对应的id如何处理*/
                $("#studentsGroup .groupName").text(searchtxt).attr("data", searchId);
                $("#myModal").modal("hide");
            });

        });
        function getResults(pageNo) {
            GrpName = $("#studentG").val().trim();
            $.easyPost("@Url.Action("GetGrpList", "GrpManage")", { "PageNO": pageNo, "PageSize": 10, "GrpName": GrpName }, function (data) {
                var _html = "";
                if (!data.result) {
                    showTips.open(data.message); return;
                }
                if (data.rows.length > 0) {
                    var _rows = data.rows, _rowL = _rows.length;
                    opts = {
                        totalPages: data.totalPage,
                        total: data.total,
                        currentPage: pageNo,
                        onPageClicked: function (event, originalEvent, type, page) {
                            getResults(page);
                        }
                    };
                    initialPaginator(opts,"PageTool", "PageInfo");
                    for (var i = 0; i < _rowL; i++) {
                        var item = _rows[i];
                        _html += '<li data="' + item.Entity .Id+ '" class="list-group-item">' + item.Entity.GroupName + '</li>';
                    }
                    $("#well").show();
                }
                else { _html = '<li style="text-align:center">没有搜索到匹配项</li>'; $("#well").hide(); }
                $listgroup1.html(_html);

            } );
        }

    </script>
</body>
</html>